package com.cal.utms.action.dealing;

import com.cal.utms.dao.dealing.DealDao;
import com.cal.utms.dto.dealing.ShortMaturityDto;
import com.cal.utms.entity.Deal;
import com.cal.utms.model.dealing.ShortMaturityModel;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class ShortMaturityAction extends ActionSupport implements ModelDriven<ShortMaturityDto> {

	private static final long serialVersionUID = 1L;

	ShortMaturityDto shortMaturityDto = new ShortMaturityDto();

	@Override
	public ShortMaturityDto getModel() {
		return this.shortMaturityDto;
	}

	public String getConfDeals() {
		DealDao dealDao = new DealDao();
		shortMaturityDto.setDealList(dealDao.queryConfirmedDeals());
		return Action.SUCCESS;
	}

	public String doShortMature() {
		if (shortMaturityDto.getDealId() == 0) {
			shortMaturityDto.setStatus("Cannot Find Deal");
			shortMaturityDto.setSuccess(false);
			return Action.SUCCESS;
		} else if (shortMaturityDto.getNewMaturityDate() == null) {
			shortMaturityDto.setStatus("Invalid New Matuarity Date");
			shortMaturityDto.setSuccess(false);
			return Action.SUCCESS;
		} else {
			ShortMaturityModel shortMaturityModel = new ShortMaturityModel();
			Deal deal = shortMaturityModel.doShortMature(shortMaturityDto);
			shortMaturityDto.setDealCode(deal.getDealCode());
			shortMaturityDto.setSuccess(true);
		}
		return Action.SUCCESS;
	}

}
